﻿using System;
using NewLife.CommonEntity;
using NewLife.CommonEntity.Web;
using XCode;
using XCode.DataAccessLayer;

namespace XTLCMS
{
    public class XTLCMSManagerProvider : CommonManageProvider<XAdmin>, ICommonManageProvider
    {
        public override Type MenuType { get { return typeof(XMenu); } }

        public override Type RoleType { get { return typeof(XRole); } }

        public override Type RoleMenuType { get { return typeof(XRoleMenu); } }

        public override Type LogType { get { return typeof(XLog); } }

        /// <summary>重写菜单</summary>
        IMenu ICommonManageProvider.MenuRoot { get { return XMenu.Root; } }
    }

    [BindTable("Menu", Description = "系统菜单", ConnName = "XTLDB", DbType = DatabaseType.SqlServer)]
    public class XMenu : Menu<XMenu> { }

    [BindTable("Role", Description = "系统角色", ConnName = "XTLDB", DbType = DatabaseType.SqlServer)]
    public class XRole : Role<XRole, XMenu, XRoleMenu> { }

    [BindTable("RoleMenu", Description = "系统角色菜单", ConnName = "XTLDB", DbType = DatabaseType.SqlServer)]
    public class XRoleMenu : RoleMenu<XRoleMenu> { }

    public class XTLCMSEntityForm : EntityForm2, IEntityForm
    {
        protected override void SaveFormSuccess()
        {
            string[] u = EntityType.ToString().Split(".");
            
            JscriptMsg("修改成功啦！", u[u.Length-1] + ".aspx", "Success");
            //this.Page.ClientScript.RegisterStartupScript(base.GetType(), "JsPrint", "parent.jsprint('这是为了什么呢？');", true);
        }

        /// <summary>
        /// 添加编辑删除提示
        /// </summary>
        /// <param name="msgtitle">提示文字</param>
        /// <param name="url">返回地址</param>
        /// <param name="msgcss">CSS样式</param>
        protected void JscriptMsg(string msgtitle, string url, string msgcss)
        {
            string msbox = "parent.jsprint(\"" + msgtitle + "\", \"" + url + "\", \"" + msgcss + "\")";
            this.Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "JsPrint", msbox, true);
            //JscriptMsg("修改模型成功啦！", "Classis.aspx", "Success", "parent.loadChannelTree");
        }

        /// <summary>
        /// 带回传函数的添加编辑删除提示
        /// </summary>
        /// <param name="msgtitle">提示文字</param>
        /// <param name="url">返回地址</param>
        /// <param name="msgcss">CSS样式</param>
        /// <param name="callback">JS回调函数</param>
        protected void JscriptMsg(string msgtitle, string url, string msgcss, string callback)
        {
            string msbox = "parent.jsprint(\"" + msgtitle + "\", \"" + url + "\", \"" + msgcss + "\", " + callback + ")";
            this.Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "JsPrint", msbox, true);
        }
    }

}